home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  2.5 KB  |  97 lines

  1. /* error.c - fprintf(stderr, then die - */
  2.  
  3. /* Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of Gas, the GNU Assembler.
  6.  
  7. The GNU assembler is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  9. accepts responsibility to anyone for the consequences of using it
  10. or for whether it serves any particular purpose or works at all,
  11. unless he says so in writing.  Refer to the GNU Assembler General
  12. Public License for full details.
  13.  
  14. Everyone is granted permission to copy, modify and redistribute
  15. the GNU Assembler, but only under the conditions described in the
  16. GNU Assembler General Public License.  A copy of this license is
  17. supposed to have been given to you along with the GNU Assembler
  18. so you can know your rights and responsibilities.  It should be
  19. in a file named COPYING.  Among other things, the copyright
  20. notice and this notice must be preserved on all copies.  */
  21.  
  22. #ifdef    DOCUMENTATION
  23.  
  24. NAME
  25.     error() - fprintf(stderr, then die
  26.  
  27. INDEX
  28.     error()
  29.     exit()
  30.     EXIT_FATAL
  31.  
  32. SYNOPSIS
  33.     format fmt;
  34.     
  35.     error (fmt, foo, bar, garply, quux, ... );
  36.     /* no return */
  37.  
  38. DESCRIPTION
  39.     This is just like printf() except:
  40.     (1)    The output is directed to stderr;
  41.     (2)    After output, the program exit()s with status EXIT_FATAL.
  42.  
  43.     It is used to allow brief handling of unexpected conditions by
  44.     printing the value of selected variables then dying. Also, if
  45.     you use error() as your standard way out of difficult situations,
  46.     and deny() as your standard way out of "impossible" conditions,
  47.     then 2 breakpoints will catch most programs, and you can
  48.     back-trace the stack to find out why.
  49.  
  50. INTERNAL
  51.     The mechanism is kludgy, but so is <varargs.h>. All "C's" I have used,
  52.     the trick has worked. It has to (mostly) work because a function MUST
  53.     be able to find its arglist, and can never rely on an explicit
  54.     argument count, so most implementers do it the pdp-11 way.
  55.  
  56. EXAMPLES
  57.     error ("warp factor overflow in line %d of file %s",
  58.         __LINE__, __FILE__);
  59.  
  60. AUTHORS
  61.     Dean Elsner, after DECUS C.
  62.  
  63. #endif                /* #ifdef DOCUMENTATION */
  64.  
  65.  
  66.  
  67. /* #include "style.h" */
  68. #include <stdio.h>
  69.  
  70. #ifndef NO_VARARGS
  71. #include <varargs.h>
  72. #endif
  73.  
  74. #define EXIT_FATAL (2)
  75.  
  76.  
  77. #ifdef NO_VARARGS
  78. /*VARARGS1*/
  79. void
  80. error(fmt,args)
  81.      char * fmt;
  82.  
  83. {
  84.   _doprnt (fmt, &args, stderr);
  85.   exit (EXIT_FATAL);
  86. }
  87. #else
  88. void
  89. error(fmt,va_alist)
  90. char *fmt;
  91. va_dcl
  92. {
  93.     vfprintf(stderr,fmt,va_alist);
  94.     exit(EXIT_FATAL);
  95. }
  96. #endif
  97.